%function [] = softMaxControl()

%%%%%%%%%%  call input_extraction  %%%%%%%%%%%%%
load groundTruth.txt;
load saliency.log;
load Track_data.txt;
load boards.dat;

G = groundTruth;
sal = saliency;
td = Track_data;

interpolatedG = interpolate(G);
nFrames = size(interpolatedG,1);


newTd = td(72:72+nFrames-1,:);

newSal = sal(72:72+nFrames-1,:);

lecturer_tracking_scale_factor = 640/2560;
saliency_tracking_scale_factor = 640/1920;

tdFinal = newTd(:,2:3)*lecturer_tracking_scale_factor;
gtFinal = interpolatedG(:,2:3);
salFinal = newSal(:,2:3)*saliency_tracking_scale_factor;%Assuming that the 2nd and 3rd are the useful columns else include 4th column


%zoom ground truth
whos -file zoom_Data.mat;
load('zoom_Data.mat','flag1');
zoomgt = flag1(:,2);

m = size(zoomgt,1);
tdFinal = tdFinal(1:m,:);
salFinal = salFinal(1:m,:);
gtFinal = gtFinal(1:m,:);

%use these matrices for learning
features = [tdFinal salFinal];
gtFinal;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%boundaries between boards
bdry1 =  (boards(1,2) + boards(2,1))/2*saliency_tracking_scale_factor; %(between board 1 and 2)
bdry2 =  (boards(2,2) + boards(3,1))/2*saliency_tracking_scale_factor; %(between board 1 and 2)
%board mid-points
board1x = (boards(1,1) + boards(1,2))/2;
board2x = (boards(2,1) + boards(2,2))/2;
board3x = (boards(3,1) + boards(3,2))/2;
boardsy = (boards(1,3) + boards(1,4))/2;

s_gt = getState(gtFinal(:,1), gtFinal(:,2),zoomgt,bdry1,bdry2);
%theta = softMaxLearn(features,s_gt);

addpath(genpath('./LIBSVM/'));
model =  svmtrain(s_gt, features);
[s_out, accuracy, decision_values] = svmpredict(s_gt, features, model);

[x,y,z] = stateToGround(s_out,board1x,board2x,board3x,boardsy);
spanX = 2;
spanY = 2;
spanZ = 2;
[xc,yc,zoomFactor] = smoothOutput(x,y,z,spanX, spanY, spanZ);
xc1 = xc(1:1000,:);
yc1 = yc(1:1000,:);
zoomFactor1 = zoomFactor(1:1000,:);
showVid('2010_EE261_L23_short.yuv','outputVideo.yuv', xc1, yc1, zoomFactor1);